using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the CompanyCategory class.
	/// </summary>
	[Serializable]
	public partial class CompanyCategoryCollection : ActiveList<CompanyCategory, CompanyCategoryCollection> 
	{	   
		public CompanyCategoryCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CompanyCategory table.
	/// </summary>
	[Serializable]
	public partial class CompanyCategory : ActiveRecord<CompanyCategory>
	{
		#region .ctors and Default Settings
		
		public CompanyCategory()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public CompanyCategory(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public CompanyCategory(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public CompanyCategory(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CompanyCategory", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarCompanyCategoryID = new TableSchema.TableColumn(schema);
				colvarCompanyCategoryID.ColumnName = "CompanyCategoryID";
				colvarCompanyCategoryID.DataType = DbType.Int32;
				colvarCompanyCategoryID.MaxLength = 0;
				colvarCompanyCategoryID.AutoIncrement = true;
				colvarCompanyCategoryID.IsNullable = false;
				colvarCompanyCategoryID.IsPrimaryKey = true;
				colvarCompanyCategoryID.IsForeignKey = false;
				colvarCompanyCategoryID.IsReadOnly = false;
				colvarCompanyCategoryID.DefaultSetting = @"";
				colvarCompanyCategoryID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCompanyCategoryID);
				
				TableSchema.TableColumn colvarCompanyCode = new TableSchema.TableColumn(schema);
				colvarCompanyCode.ColumnName = "CompanyCode";
				colvarCompanyCode.DataType = DbType.Int32;
				colvarCompanyCode.MaxLength = 0;
				colvarCompanyCode.AutoIncrement = false;
				colvarCompanyCode.IsNullable = true;
				colvarCompanyCode.IsPrimaryKey = false;
				colvarCompanyCode.IsForeignKey = true;
				colvarCompanyCode.IsReadOnly = false;
				colvarCompanyCode.DefaultSetting = @"";
				
					colvarCompanyCode.ForeignKeyTableName = "Company";
				schema.Columns.Add(colvarCompanyCode);
				
				TableSchema.TableColumn colvarCategoryCode = new TableSchema.TableColumn(schema);
				colvarCategoryCode.ColumnName = "CategoryCode";
				colvarCategoryCode.DataType = DbType.Int32;
				colvarCategoryCode.MaxLength = 0;
				colvarCategoryCode.AutoIncrement = false;
				colvarCategoryCode.IsNullable = true;
				colvarCategoryCode.IsPrimaryKey = false;
				colvarCategoryCode.IsForeignKey = true;
				colvarCategoryCode.IsReadOnly = false;
				colvarCategoryCode.DefaultSetting = @"";
				
					colvarCategoryCode.ForeignKeyTableName = "Category";
				schema.Columns.Add(colvarCategoryCode);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = false;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				
						colvarDateAdded.DefaultSetting = @"(getdate())";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = false;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				
						colvarDateModified.DefaultSetting = @"(getdate())";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("CompanyCategory",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("CompanyCategoryID")]
		public int CompanyCategoryID 
		{
			get { return GetColumnValue<int>("CompanyCategoryID"); }

			set { SetColumnValue("CompanyCategoryID", value); }

		}

		  
		[XmlAttribute("CompanyCode")]
		public int? CompanyCode 
		{
			get { return GetColumnValue<int?>("CompanyCode"); }

			set { SetColumnValue("CompanyCode", value); }

		}

		  
		[XmlAttribute("CategoryCode")]
		public int? CategoryCode 
		{
			get { return GetColumnValue<int?>("CategoryCode"); }

			set { SetColumnValue("CategoryCode", value); }

		}

		  
		[XmlAttribute("DateAdded")]
		public DateTime DateAdded 
		{
			get { return GetColumnValue<DateTime>("DateAdded"); }

			set { SetColumnValue("DateAdded", value); }

		}

		  
		[XmlAttribute("DateModified")]
		public DateTime DateModified 
		{
			get { return GetColumnValue<DateTime>("DateModified"); }

			set { SetColumnValue("DateModified", value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Category ActiveRecord object related to this CompanyCategory
		/// 
		/// </summary>
		public Adex.Category Category
		{
			get { return Adex.Category.FetchByID(this.CategoryCode); }

			set { SetColumnValue("CategoryCode", value.CategoryID); }

		}

		
		
		/// <summary>
		/// Returns a Company ActiveRecord object related to this CompanyCategory
		/// 
		/// </summary>
		public Adex.Company Company
		{
			get { return Adex.Company.FetchByID(this.CompanyCode); }

			set { SetColumnValue("CompanyCode", value.CompanyCode); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int? varCompanyCode,int? varCategoryCode,DateTime varDateAdded,DateTime varDateModified)
		{
			CompanyCategory item = new CompanyCategory();
			
			item.CompanyCode = varCompanyCode;
			
			item.CategoryCode = varCategoryCode;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varCompanyCategoryID,int? varCompanyCode,int? varCategoryCode,DateTime varDateAdded,DateTime varDateModified)
		{
			CompanyCategory item = new CompanyCategory();
			
				item.CompanyCategoryID = varCompanyCategoryID;
				
				item.CompanyCode = varCompanyCode;
				
				item.CategoryCode = varCategoryCode;
				
				item.DateAdded = varDateAdded;
				
				item.DateModified = varDateModified;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string CompanyCategoryID = @"CompanyCategoryID";
			 public static string CompanyCode = @"CompanyCode";
			 public static string CategoryCode = @"CategoryCode";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
						
		}

		#endregion
	}

}

